﻿using CarterWechatServer.BizLogic.Order;
using CarterWechatServer.BizModel.Order;
using CarterWechatServer.Util.Result;
using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace CarterWechatServer.WebApi.Controllers
{
    /// <summary>
    /// 订单控制器
    /// </summary>
    [Authorize]
    public class OrderController : ApiController
    {
        private OrderService _orderService;

        /// <summary>
        /// 构造方法
        /// </summary>
        public OrderController()
        {
            _orderService = new OrderService();
        }

        /// <summary>
        /// 订单提交
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public DataResult<int> Post(OrderSubmitInput input)
        {
            input.UserId = HttpContext.Current.User.Identity.GetUserId<int>();

            int id = _orderService.OrderSubmit(input);
            return new DataResult<int>(id);
        }

        /// <summary>
        /// 订单详情
        /// </summary>
        /// <param name="id">订单id</param>
        /// <returns></returns>
        public DataResult<OrderDetailOutput> Get(int id)
        {
            OrderDetailOutput output = _orderService.OrderDetail(id);

            return new DataResult<OrderDetailOutput>(output);
        }

        public DataResult<List<OrderListOutput>> Get()
        {
            List<OrderListOutput> outputs = _orderService.OrderList();
            return new DataResult<List<OrderListOutput>>(outputs);
        }
    }
}
